package cre.spring.javaconfig5;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;

/**
 * @Author guchenbo
 * @Date 2019/4/20.
 */
@ComponentScan("cre.spring.javaconfig5")
public class AppBoot {
    public static void main(String[] args) {
        //       m1();
        m2();
    }

    private static void m1() {
        ApplicationContext context = new AnnotationConfigApplicationContext(AppBoot.class);
        Foo foo = context.getBean("foo", Foo.class);
        foo.say();

        JavaConfig config = context.getBean("javaConfig", JavaConfig.class);
        System.out.println(config);
    }

    private static void m2() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
                context.register(AppBoot.class);
//        context.scan("cre.spring.javaconfig5");
        System.out.println(context.getBeanDefinitionCount());

        String[] names = context.getBeanDefinitionNames();
        for (String name : names) {
            System.out.println(name);
        }

        context.refresh();
    }
}
